]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dbusService: Watch shell name from implementation
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 4 Sep 2024 17:39:41 +0000 (19:39 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 4 Feb 2025 11:22:59 +0000 (12:22 +0100)
The service implementation already has to resolve the shell's
unique name to exclude it from sender tracking.

It can just as well take care of watching the shell D-Bus name,
which simplifies the code and will allow for more flexibility
when handling the shell disappearing from the bus.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3463>

js/dbusServices/dbusService.js

index 941deaf294920682df4397b07c49fa30e4db34b7..f1bc4c6f6496d7d151407e637ba8fcf7fb012655 100644 (file)
@@ -23,7 +23,15 @@ export class ServiceImplementation {
         this._senders = new Map();
         this._holdCount = 0;
 
-        this._shellName = this._getUniqueShellName();
+        // Bail out when not running under gnome-shell
+        Gio.DBus.watch_name(Gio.BusType.SESSION,
+            'org.gnome.Shell',
+            Gio.BusNameWatcherFlags.NONE,
+            (c, name, owner) => (this._shellName = owner),
+            () => {
+                this._shellName = null;
+                this.emit('shutdown');
+            });
 
         this._hasSignals = this._dbusImpl.get_info().signals.length > 0;
         this._shutdownTimeoutId = 0;
@@ -156,26 +164,6 @@ export class ServiceImplementation {
             that._queueShutdownCheck();
         };
     }
-
-    _getUniqueShellName() {
-        try {
-            const res = Gio.DBus.session.call_sync(
-                'org.freedesktop.DBus',
-                '/org/freedesktop/DBus',
-                'org.freedesktop.DBus',
-                'GetNameOwner',
-                new GLib.Variant('(s)', ['org.gnome.Shell']),
-                null,
-                Gio.DBusCallFlags.NONE,
-                -1,
-                null);
-            const [name] = res.deepUnpack();
-            return name;
-        } catch (e) {
-            console.warn(`Failed to resolve shell name: ${e.message}`);
-            return '';
-        }
-    }
 }
 Signals.addSignalMethods(ServiceImplementation.prototype);
 
@@ -189,13 +177,6 @@ export class DBusService {
     }
 
     async runAsync() {
-        // Bail out when not running under gnome-shell
-        Gio.DBus.watch_name(Gio.BusType.SESSION,
-            'org.gnome.Shell',
-            Gio.BusNameWatcherFlags.NONE,
-            null,
-            () => this._loop.quit());
-
         this._service.register();
 
         let flags = Gio.BusNameOwnerFlags.ALLOW_REPLACEMENT;